1. Field
One or more embodiments relate to an embedded system, and more particularly, to a method and apparatus for preventing a stack overflow in an embedded system.
2. Description of the Related Art
An embedded system is a system in which a microprocessor or a microcontroller is embedded and designed to perform a dedicated function. The embedded system is also conventionally referred to as a particular application system that is a part of a large system, and includes hardware or software for performing a dedicated function. The embedded system is applied to various kinds of fields such as a control field including factory automation, home automation, robot control, and process control, a terminal device field including mobile phones, personal digital assistants (PDAs), smart-phones, and location-based services (LBSs), an information domestic appliance field including printers, Internet refrigerators, games, and high-definition televisions (HDTVs), and a network device field including switches, routers, home servers, and home gateways.
The embedded system has strict restrictions in terms of cost, size, power consumption, and the like, such that it is not preferable that resources be allocated for a future request that cannot be predicted. Therefore, a resource request in a worst-case scenario has to be accurately analyzed in advance, and this analysis of the resource request also has to be performed on resources, such as memory, which can be easily and dynamically allocated and returned.
A stack is one of the resources of the embedded system that is most frequently used. Hence, a memory resource in the entire system is limited, so that a stack region is also limited. Therefore, when a particular task uses all of the stack allocated to the task and tries to access memory that is outside the region reserved for the stack to store information on the task, a problem occurs, that is, a stack overflow occurs.
Techniques for preventing the stack overflow are classified as a static analysis technique and a run-time check technique. The static analysis technique that is used to prevent stack overflow does not execute the program, however, analyzes the program itself. According to a type of a system that is to be analyzed, the static analysis technique that is used to prevent stack overflow is classified as a technique for analyzing a binary image and a technique for analyzing a source code. The static analysis technique involves a stack depth analysis technique using a control flow graph (CFG) and a technique using an abstract interpretation. According to the static analysis technique, since the amount of stack used is predicted offline, a run-time overhead does not occur. However, this technique cannot be applied to a system in which the components of the system are dynamically changed. Therefore, the static analysis technique is mainly applied to a closed system in which the components of the system are not changed.
The run-time check technique that is used to prevent stack overflow does not predict the amount of stack used, however, allocates a predetermined stack and checks whether the stack overflow occurs during run-time. The run-time check technique includes a compiler-generated run-time check technique and a non-executable stack technique, and the run-time check technique can be applied to a system in which components of the system are dynamically changed. However, the run-time check technique needs the support of compilers or hardware. Moreover, since whether the stack overflow occurs is continuously checked during run-time, a run-time overhead may occur.